package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.UseCountView;
import com.sl.au.repository.UseCountRepository;
import com.sl.au.service.UseCountService;

@Service("UseCountService")
@Transactional
public class UseCountServiceImpl extends BaseServiceImpl implements UseCountService{

	@Autowired
	UseCountRepository useCountRepository;
	
	@Override
	public List<UseCountView> getMyPage(int start, int length, String key) {
		Page<UseCountView> pages=null;
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"cPartCode");//排序
		if(key == null || key == ""){
			pages=useCountRepository.getPage( pageable);
		}else{
			pages=useCountRepository.getPage(key, pageable);
		}
		return pages.getContent();
	}

	@Override
	public long getCount(String key) {
		long count = 0;
		if(key == null || key == "" ){
			count = useCountRepository.getCount();
		}else{
			count = useCountRepository.getCount(key);
		}
		return count;
	}

	@Override
	public UseCountRepository getRepository() {
		// TODO Auto-generated method stub
		return this.useCountRepository;
	}

}
